package com.oreilly;
import java.sql.*;


public class PayoffBean {
	Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
//    int currentID;
//    String currentName;
//    Boolean currentAorD;
//    String currentDes;
    
    private String payoffTable = new String();

	public String getPayoffTable() {
//		payoffTable = "<table style=\"text-align: left; width: 983px; height: 60px;\" border=\"1\" cellpadding=\"2\" cellspacing=\"2\">";
//		payoffTable += "<tbody>";
//		payoffTable += "<tr><td>ID</td><td>Name</td><td>AorD</td><td>Type</td><td>Des</td><tr>";


		// Execute an SQL query, get a ResultSet
		try {
			rs = stmt.executeQuery("SELECT * FROM Payoff");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			payoffTable = e.getMessage();
			return payoffTable;
		}
	      try {
			while(rs.next()) {
			      try {
					payoffTable += "<tr>";
					payoffTable += "<td>" + rs.getInt("ID") + "</td>";
					payoffTable += "<td><input value=\"" + rs.getString("name") + "\"></td>";
//					payoffTable += "<td>" + rs.getBoolean("AorD") + "</td>";
					
					payoffTable += "<td><select>";
					Boolean isA = rs.getBoolean("AorD");
					if(isA){
						payoffTable += "<option value=1 selected=\"selected\">攻击</option><option value=0>防御</option></select>" + "</td>";				
					}
					else{
						payoffTable += "<option value=1>攻击</option><option value=0 selected=\"selected\">防御</option></select>" + "</td>";
					}
					
					payoffTable += "<td><select>";
					int type = rs.getInt("Type");
					switch(type){
					case 1:
						payoffTable += "<option value=1 selected=\"selected\">DDoS</option><option value=2>DNS</option><option value=3>蠕虫</option>";
						break;
					case 2:
						payoffTable += "<option value=1>DDoS</option><option value=2 selected=\"selected\">DNS</option><option value=3>蠕虫</option>";
						break;
					case 3:
						payoffTable += "<option value=1>DDoS</option><option value=2>DNS</option><option value=3  selected=\"selected\">蠕虫</option>";
						break;
					}
					payoffTable += "</select>" + "</td>";
//					payoffTable += "<td><input value=\"" + rs.getInt("Type") + "\"></td>";
					
					
					payoffTable += "<td><input value=\"" + rs.getString("Des") + "\"></td>";
					payoffTable +="<td>" + "<input type=\"submit\" value=\"保存\">" + "</td>";
					payoffTable +="<td>" + "<input type=\"submit\" value=\"删除\">" + "</td>";
					payoffTable += "<tr>";
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					payoffTable = e.getMessage();
					return payoffTable;
				}
			    }
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			payoffTable = e.getMessage();
			return payoffTable;
		}

		
		payoffTable += "</tbody>";
		payoffTable += "</table>";
		return payoffTable;
	}

	
	public PayoffBean(){
		try {
			conn = DBSetting.GetConnection();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			stmt = conn.createStatement();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	
}
